#ifndef VNCVIEWWIDGET_H
#define VNCVIEWWIDGET_H

#include <QWidget>
#include <QThread>

#include "rfb/rfbclient.h"
#include "rfb/rfbconfig.h"

#include "vnc_client/vncrecvthread.h"
#include "vnc_client/vncsendworker.h"

class VncViewWidget : public QWidget
{
    Q_OBJECT
public:
    explicit VncViewWidget(QString ip, quint32 port, QWidget *parent = nullptr);
    ~VncViewWidget();

    void start();
    void stop();
    inline bool isStarted(){
        return _startFlag;
    }

    void updateImage(const QImage& image);

    void paintEvent(QPaintEvent *event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void closeEvent(QCloseEvent* event) override;

private:
    QImage _image;
    rfbClient *_cl;
    QString _ip;
    quint32 _port;
    bool _startFlag = false;

    QThread* _vncSendThread;
    VNCSendWorker* _vncSendWorker;
    VNCRecvThread* _vncRecvThread;

signals:
    void sendMouseState(rfbClient* cl, int x, int y, int button);
    void fullWindowCloseSignal();

public slots:
};

#endif // VNCVIEWWIDGET_H
